package com.ruoyi.purchase.service.impl;

import com.ruoyi.purchase.domain.OrderDetail;
import com.ruoyi.purchase.mapper.ChangeDetailMapper;
import com.ruoyi.purchase.mapper.OrderDetailMapper;
import com.ruoyi.purchase.service.IOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单详情Service业务层处理
 *
 * @author kevinness
 * @date 2025-01-03
 */
@Service
public class OrderDetailService implements IOrderDetailService
{
    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Autowired
    private ChangeDetailMapper changeDetailMapper;

    /**
     * 查询订单详情
     *
     * @param orderNo 订单详情主键
     * @return 订单详情
     */
    @Override
    public List<OrderDetail> selectOrderDetailByOrderNo(String orderNo)
    {
        return orderDetailMapper.selectOrderDetailByOrderNo(orderNo);
    }

    /**
     * 查询订单详情列表
     *
     * @param OrderDetail 订单详情
     * @return 订单详情
     */
    @Override
    public List<OrderDetail> selectOrderDetailList(OrderDetail OrderDetail)
    {
        return orderDetailMapper.selectOrderDetailList(OrderDetail);
    }

    /**
     * 新增订单详情
     *
     * @param OrderDetail 订单详情
     * @return 结果
     */
    @Override
    public int insertOrderDetail(OrderDetail OrderDetail)
    {
        return orderDetailMapper.insertOrderDetail(OrderDetail);
    }

    /**
     * 修改订单详情
     *
     * @param OrderDetail 订单详情
     * @return 结果
     */
    @Override
    public int updateOrderDetail(OrderDetail OrderDetail)
    {
        return orderDetailMapper.updateOrderDetail(OrderDetail);
    }

    /**
     * 批量修改订单详情
     *
     * @param orderDetails 订单详情列表
     * @return 结果
     */
    @Override
    public int updateOrderDetailList(List<OrderDetail> orderDetails){
        int result = 1;
        for (OrderDetail orderDetail : orderDetails) {
            result = orderDetailMapper.updateOrderDetail(orderDetail);
            if(result <= 0){
                return result;
            }
        }
        return result;
    }

    /**
     * 批量删除订单详情
     *
     * @param orderNos 需要删除的订单详情主键
     * @return 结果
     */
    @Override
    public int deleteOrderDetailByOrderNos(String[] orderNos)
    {
        return orderDetailMapper.deleteOrderDetailByOrderNos(orderNos);
    }

    /**
     * 删除订单详情信息
     *
     * @param orderNo 订单详情主键
     * @return 结果
     */
    @Override
    public int deleteOrderDetailByOrderNo(String orderNo)
    {
        return orderDetailMapper.deleteOrderDetailByOrderNo(orderNo);
    }

    /**
     * 根据批号获取订单详情
     */
    @Override
    public OrderDetail selectOrderDetailByRawProductBatch(String rawProductBatch){
        return orderDetailMapper.selectOrderDetailByRawProductBatch(rawProductBatch);
    }
}
